

plotdata1880 =
  analysis_df_1 %>%
  mutate(big_city = city %in% c("new york, ny", "cleveland, oh", "chicago, il",
                                "akron, oh", "manchester, nh", "quincy, ma"
                                )*1) %>%
  mutate(city = case_when(city == "new york, ny" ~ "New York, NY",
                          city == "cleveland, oh" ~ "Cleveland, OH",
                          city == "chicago, il" ~ "Chicago, IL",
                          city == "akron, oh" ~ "Akron, OH",
                          city == "manchester, nh" ~ "Manchester, NH",
                          city == "quincy, ma" ~ "Quincy, MA",
                          TRUE ~ city)) %>%
  filter(YEAR == 1880)

plot1880 <-
  plotdata1880 %>%
  ggplot(aes(x=white_x_foreign_born*100, y = govt_white_x_foreign_born*100, alpha = factor(big_city), color = factor(big_city), label = city, size = n_total)) +
  geom_point() +
  scale_alpha_manual(values = c(0.3, 0.8)) +
  geom_abline(slope = 1, intercept = 0, linetype = "dashed") +
  theme_bw() +
  theme(panel.grid.minor = element_blank(), 
        panel.grid.major.x = element_blank(),
        axis.line.y.left = element_blank(),
        legend.position = "none",
        strip.background = element_blank(),
        legend.title = element_blank(),
        axis.ticks.y.left = element_blank(),
        axis.line = element_line(colour = "black"),
        panel.border = element_blank()) +
  scale_color_manual(values = c("grey50", "black")) +
  ylab("Foreign-Born Whites in Government (%)") +
  xlab("Foreign-Born Whites in Population (%)") +
  geom_text_repel(data = subset(plotdata1880, big_city == 1),
                  size          = 3,
                  box.padding   = 1,
                  point.padding = 0.5,
                  force         = 100,
                  segment.size  = 0.2,
                  segment.color = "black") +
  theme(legend.position = "none") +
  theme(text=element_text(size=10))

ggsave('./replication_file/_5_outputs/figures/figure_1a.png', plot = plot1880, width=8, height=5)
#ggsave('../Apps/Overleaf/merit paper/outputs/scatter_city_size_1880.png',plot = plot1880, width=6, height=5)


plotdata1930 <-
  analysis_df_1 %>%
  mutate(big_city = city %in% c("new york, ny", "cleveland, oh", "chicago, il",
                                "akron, oh", "manchester, nh", "quincy, ma")*1) %>%
  mutate(city = case_when(city == "new york, ny" ~ "New York, NY",
                          city == "cleveland, oh" ~ "Cleveland, OH",
                          city == "chicago, il" ~ "Chicago, IL",
                          city == "akron, oh" ~ "Akron, OH",
                          city == "manchester, nh" ~ "Manchester, NH",
                          city == "quincy, ma" ~ "Quincy, MA",
                          TRUE ~ city)) %>%
  filter(YEAR == 1930)

plot1930 <-
  plotdata1930 %>%
  ggplot(aes(x=white_x_foreign_born*100, y = govt_white_x_foreign_born*100, alpha = factor(big_city), color = factor(big_city), label = city, size = n_total)) +
  geom_point() +
  scale_alpha_manual(values = c(0.3, 0.8)) +
  geom_abline(slope = 1, intercept = 0, linetype = "dashed") +
  theme_bw() +
  theme(panel.grid.minor = element_blank(), 
        panel.grid.major.x = element_blank(),
        axis.line.y.left = element_blank(),
        legend.position = "none",
        strip.background = element_blank(),
        legend.title = element_blank(),
        axis.ticks.y.left = element_blank(),
        axis.line = element_line(colour = "black"),
        panel.border = element_blank()) +
  scale_color_manual(values = c("grey50", "black")) +
  ylab("Foreign-Born Whites in Government (%)") +
  xlab("Foreign-Born Whites in Population (%)") +
  geom_text_repel(data = subset(plotdata1930, big_city == 1),
                  size          = 3,
                  box.padding   = 1,
                  point.padding = 0.5,
                  force         = 30,
                  segment.size  = 0.2,
                  segment.color = "black") +
  theme(legend.position = "none") +
  theme(text=element_text(size=10))


ggsave('./replication_file/_5_outputs/figures/figure_1b.png', plot = plot1930, width=8, height=5)
#ggsave('../Apps/Overleaf/merit paper/outputs/scatter_city_size_1930.png',plot = plot1930, width=6, height=5)

  


